<template lang="">
		<view class="home">
			<u-upload custom-btn ref="uUpload"  :auto-upload="false" :action="action" name="url" :form-data="formData" :header="header" :before-upload="beforeUpload" max-count="1">
				<view slot="addBtn" class="upload-slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
					<view class="content">
						<view class="addIcon">
							<u-icon class="" name="plus" size="35" color="#fff"></u-icon>
						</view>
						<text style="color:#bebebe;">上传图片</text>
					</view>
					
				</view>
			</u-upload>
			<u-toast ref="uToast" />
		</view>
     
</template>
<script>
	
export default {
    data() {
    	return {
			fileList:[],
			action: uni.getStorageSync('baseUrl')+'api/Upload/uploadFile',
			formData:{
				type:'image',
			},
			header: {
				token : uni.getStorageSync('token')
			},
			resImgUrl:'',
		};
    },
    props:{
  //   	inputArr :{
		// 	type:Array,
		// 	default:()=>{return []}
		// }, 
		
    },
	methods:{
		async beforeUpload(index,list){
			console.log(111);
			console.log(index);
			console.dir(list);
		},
		async uploadImg(){
			let _this = this
			if(!this.$refs.uUpload.$data.lists.length){
				return _this.$emit('sucColse')
			}
		    let	url = this.$refs.uUpload.$data.lists[0].url
			
			// #ifdef MP-WEIXIN
			uni.showLoading({
				title:'加载中'
			})
			await wx.uploadFile({
				url: this.action,
				formData:this.formData,
				filePath:url,
				name:'url',
				timeout:'60000',
				header: {
					token:  uni.getStorageSync('token')
				},
				success(res) {
					console.log(res);
					if(res.statusCode ==200){
						_this.$refs.uToast.show({
								title: '上传图片成功',
								type: 'success',
						})
						_this.resImgUrl = JSON.parse( res.data).data.url
						_this.$emit('sucColse')
						// console.log(_this);
						// console.log(_this.$parent);
						// _this.$parent.$refs.popup.close()
					}
				},
				fail(err){
					console.log(err);
					_this.$refs.uToast.show({
							title: '上传图片失败,请重新尝试',
							type: 'error',
					})
				},
				complete(){
					// 隐藏加载中
					uni.hideLoading()
				}
			})
			// #endif
		}
	},
	mounted() {
	
	},
	computed:{

	},
}
</script>
<style lang="scss" scoped>
    .home{
		.upload-slot-btn{
			width: 275rpx;
			height: 275rpx;
			display: grid;
			place-items: center;
			border: 1px dashed #d2d2d2;
			border-radius: 4px;
			.content{
				display: flex;
				flex-direction: column;
				align-items: center;
				.text{}
				.addIcon{
					margin-top: 20rpx;
					background-color: #d2d2d2;
					width: 50rpx;
					height: 50rpx;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}
		}
		
	}
</style>
